home *** CD-ROM | disk | FTP | other *** search
- unit FrmAnts;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtCtrls, StdCtrls;
-
- type
- TAntsNest = class(TForm)
- Timer1: TTimer;
- Panel1: TPanel;
- Panel2: TPanel;
- Panel3: TPanel;
- Panel4: TPanel;
- Panel5: TPanel;
- Panel6: TPanel;
- Panel7: TPanel;
- procedure Timer1Timer(Sender: TObject);
- procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
- procedure FormMouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- private
- Anchor: TPoint;
- HotRect: TRect;
- DashMask: Byte;
- procedure DrawHotRect;
- procedure SetHotRect (X1, Y1, X2, Y2: Integer);
- public
- { Public declarations }
- end;
-
- var
- AntsNest: TAntsNest;
-
- implementation
-
- {$R *.DFM}
-
- procedure LineDDAProc (X, Y: Integer; Self: TAntsNest); stdcall;
- const
- DotPattern: Byte = $a0;
- var
- C: Integer;
- begin
- with Self do begin
- DashMask := DashMask shl 1;
- if DashMask = 0 then DashMask := 1;
- if (DashMask and DotPattern) <> 0 then C := Color else C := clBlack;
- SetPixel (Canvas.Handle, X, Y, ColorToRGB (C));
- end;
- end;
-
- procedure TAntsNest.FormMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- SetHotRect (X, Y, X, Y);
- end;
-
- procedure TAntsNest.FormMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer);
- begin
- if ssLeft in Shift then begin
- SetHotRect (Anchor.x, Anchor.y, X, Y);
- DrawHotRect;
- end;
- end;
-
- procedure TAntsNest.FormMouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- var
- R: TRect;
- Idx : Integer;
- begin
- for Idx := 0 to ControlCount - 1 do
- if Controls [Idx] is TPanel then with Controls [Idx] as TPanel do
- if IntersectRect (R, BoundsRect, HotRect) then Color := clYellow else Color := clBtnFace;
- end;
-
- procedure TAntsNest.SetHotRect (X1, Y1, X2, Y2: Integer);
- var
- Temp: Integer;
- begin
- // Erase previous rectangle, if any
- if not IsRectEmpty (HotRect) then begin
- InflateRect (HotRect, 1, 1);
- InvalidateRect (Handle, @HotRect, True);
- InflateRect (HotRect, -2, -2);
- ValidateRect (Handle, @HotRect);
- UpdateWindow (Handle);
- end;
-
- Anchor.x := X1; Anchor.y := Y1;
- if X1 > X2 then begin Temp := X1; X1 := X2; X2 := Temp; end;
- if Y1 > Y2 then begin Temp := Y1; Y1 := Y2; Y2 := Temp; end;
- HotRect := Rect (X1, Y1, X2, Y2);
- end;
-
- procedure TAntsNest.DrawHotRect;
- const
- StartMask: Byte = $80;
- begin
- StartMask := StartMask shr 1;
- if StartMask = 0 then StartMask := $80;
- DashMask := StartMask;
-
- with HotRect do begin
- LineDDA (Left, Top, Right, Top, @LineDDAProc, Integer (Self));
- LineDDA (Right, Top, Right, Bottom, @LineDDAProc, Integer (Self));
- LineDDA (Right, Bottom, Left, Bottom, @LineDDAProc, Integer (Self));
- LineDDA (Left, Bottom, Left, Top, @LineDDAProc, Integer (Self));
- end;
- end;
-
- procedure TAntsNest.Timer1Timer(Sender: TObject);
- begin
- DrawHotRect;
- end;
-
- end.
-
-
-